﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Ocmf.Types;

namespace Ocmf.Forms
{
    public partial class EditStopForm : Form
    {
        public Stop Stop { get; set; }

        public EditStopForm(Stop stop)
        {
            InitializeComponent();

            Stop = stop;

            countersComboBox.Items.AddRange(((Experiment)Stop.TreeView).Counters.ToArray());
            inequalityComboBox.Items.AddRange(Enum.GetNames(typeof (Inequality)));

            if (Stop.IsConditional)
            {

                conditionalRadioButton.Checked = true;
                countersComboBox.SelectedItem = Stop.Counter;
                inequalityComboBox.SelectedItem = Enum.GetName(typeof (Inequality), Stop.Inequality);
                valueNumericUpDown.Value = Stop.ConditionalValue;
            }
            else
                unconditionalRadioButton.Checked = true;
        }

        private void unconditionalRadioButton_CheckedChanged(object sender, EventArgs e)
        {
            conditionalGroupBox.Enabled = !unconditionalRadioButton.Checked;
            unconditionalLabel.Enabled =  unconditionalRadioButton.Checked;
        }

        private void buttonOk_Click(object sender, EventArgs e)
        {
            if(conditionalRadioButton.Checked)
            {
                Stop.IsConditional = true;
                Stop.Counter = countersComboBox.SelectedItem.ToString();
                Stop.Inequality = (Inequality)Enum.Parse(typeof(Inequality), inequalityComboBox.SelectedItem.ToString());
                Stop.ConditionalValue = Decimal.ToInt32(valueNumericUpDown.Value);
            }
            DialogResult = System.Windows.Forms.DialogResult.OK;
        }

        private void buttonCancel_Click(object sender, EventArgs e)
        {
            DialogResult = System.Windows.Forms.DialogResult.Cancel;
        }
    }
}
